package com.weiyan.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @author misterWei
 * @create 2020年02月25号:22点14分
 * @mailbox mynameisweiyan@gmail.com
 */
@Component
@Slf4j
public class YmlProperties implements ApplicationListener<ContextRefreshedEvent> {
    @Value("${spring.application.name}")
    private  String applicationName;

    @Autowired
    private Environment environment;
    public static  String appName;

    public YmlProperties() {
        log.info("{}",applicationName);
        appName = applicationName;
    }

    public static String getApplicationName(){
        return appName;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
       appName =  applicationName;
    }
}
